package com.xinbochuang.machine.admin.controller.certification;


import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.xinbochuang.machine.admin.domain.Certification;
import com.xinbochuang.machine.admin.service.ICertificationService;
import com.xinbochuang.machine.common.controller.BaseController;
import com.xinbochuang.machine.common.domain.TableDataInfo;
import com.xinbochuang.machine.framework.web.domain.AjaxResult;

/**
 *
 * @author 杜文博
 * @date 2020-10-09
 */
@RestController
@RequestMapping("/certification")
public class CertificationController extends BaseController {

	@Autowired
	ICertificationService certificationService;

	/**
	 * 分页查询资质列表
	 * @param certification
	 * @return
	 */
	@GetMapping("/list")
	public TableDataInfo getCertificationList(Certification certification){
		return  getDataTable(certificationService.selectList(certification));
	}

	/**
	 * 根据资质Id查询详情
	 * @param uuId
	 * @return
	 */
	@GetMapping("/detail")
	public AjaxResult getCertificationList(@RequestParam("uuid") String uuId){
		return  AjaxResult.data(certificationService.getCertById(uuId));
	}

	/**
	 * 新增资质
	 * @param certification
	 * @return
	 */
	@PostMapping("/insert")
	public AjaxResult insertCertification(@RequestBody Certification certification){
		return toAjax(certificationService.insertCertification(certification));
	}

	/**
	 * 修改资质
	 * @param certification
	 * @return
	 */
	@PutMapping("/update")
	public AjaxResult updateCertification(@RequestBody Certification certification){
		return toAjax(certificationService.updateCertification(certification));
	}

	/**
	 * 批量删除资质
	 * @param uuids
	 * @return
	 */
	@GetMapping("/delete")
	public AjaxResult deleteCertification(@RequestParam("uuids") String uuids){
		boolean result = certificationService.deleteCertification(uuids);
		if(result){
			return toAjax(result);
		}else{
			return AjaxResult.ok("该工单不在待审核状态无法删除");
		}
	}

	/**
	 * 资质文件上传
	 * @param file
	 * @return
	 * @throws IOException
	 */
	@PostMapping("/savePicByFormData")
	public AjaxResult savePicByIo(@RequestParam("file")MultipartFile file)throws
		IOException{
		System.out.println("图片上传开始");
		String fileName = certificationService.uploadFile(file);
		return AjaxResult.data(fileName);
	}

//	/**
//	 * 资质文件上传
//	 * @param
//	 * @return
//	 * @throws IOException
//	 */
//	@ResponseBody
//	@PostMapping("/uploadCAD")
//	public AjaxResult uploadCAD(@RequestBody byte[] cad)throws
//		IOException{
//		System.out.println("图片上传开始");
////		String fileName = certificationService.uploadFile(file);
//		return AjaxResult.data(cad);
//	}
}

